from django.db import models


class QUser(models.Model):
    username = models.CharField(max_length=32)
    password = models.CharField(max_length=32)
    has_store = models.IntegerField()  # 0 代表没有店铺 1 有店铺


class QuserInfo(models.Model):
    nick_name = models.CharField(max_length=32)
    phone = models.CharField(max_length=32, blank=True, null=True)
    picture = models.ImageField(upload_to="image", blank=True, null=True)
    age = models.IntegerField(blank=True, null=True)
    gender = models.CharField(max_length=8, blank=True, null=True)
    home_address = models.TextField(blank=True, null=True)
    email = models.EmailField()
    user_id = models.OneToOneField(to=QUser, on_delete=models.CASCADE)


class Address(models.Model):
    a_phone = models.CharField(max_length=32)
    recver = models.CharField(max_length=32)
    recv_address = models.TextField()
    post_number = models.CharField(max_length=32)
    user = models.ForeignKey(to=QuserInfo, on_delete=models.CASCADE)


from Store.models import Goods, Store


class Car(models.Model):
    goods_id = models.ForeignKey(to=Goods, on_delete=models.CASCADE)
    user_id = models.ForeignKey(to=QUser, on_delete=models.CASCADE)
    c_goods_number = models.IntegerField()


class Order(models.Model):
    order_id = models.CharField(max_length=32, blank=True, null=True)  # 订单编号
    g_type_number = models.IntegerField()  # 商品数量
    g_total = models.FloatField(blank=True, null=True)  # 商品总价
    g_money = models.FloatField(blank=True, null=True)  # 总价加运费
    user_id = models.ForeignKey(to=QUser, on_delete=models.CASCADE)
    address = models.ForeignKey(to=Address, on_delete=models.CASCADE)
    pay_method = models.CharField(max_length=32)  # 支付方式
    order_time = models.DateTimeField(auto_now=True)
    order_statue = models.CharField(max_length=32, default='已经支付')  # 支付状态


class OrderInfo(models.Model):
    orderId = models.ForeignKey(to=Order, on_delete=models.CASCADE)
    goods_id = models.ForeignKey(to=Goods, on_delete=models.CASCADE)
    store_id = models.ForeignKey(to=Store, on_delete=models.CASCADE)

    info_order_id = models.CharField(max_length=16)  # 订单编号
    goods_number = models.IntegerField()  # 数量
    goods_total = models.FloatField()  # 商品价格
    free_post = models.IntegerField()  # 是否包邮，0 不包邮，1 包邮
    post_money = models.FloatField()  # 邮费


# Create your models here.
